﻿namespace WMS6.Web.TaskMgmt
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.TaskMgtServiceRef;

    public class UserLicenseDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected CheckBox chkAllowCase;
        protected CheckBox chkAllowIps;
        protected CheckBox chkAllowPallet;
        protected CheckBox chkAllowPiece;
        protected CheckBox chkPermission;
        protected DropDownList ddlPermissionType;
        protected HtmlForm F6043;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnType;
        protected HtmlInputHidden hdnUserID;
        protected HtmlHead Head1;
        protected HtmlImage img1;
        protected Label lblAreaID;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblPermissionType;
        protected Label lblUserLicenseDetail;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAreaID;
        protected TextBox txtLineID;
        protected UpdatePanel up1;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("UserLicense.aspx", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                TaskManagerUserDetailInfo taskManagerUserDetailInfo = null;
                if (string.IsNullOrEmpty(this.hdnType.Value))
                {
                    taskManagerUserDetailInfo = new TaskManagerUserDetailInfo();
                }
                else
                {
                    taskManagerUserDetailInfo = base.DataEntityViewState as TaskManagerUserDetailInfo;
                }
                taskManagerUserDetailInfo.UserID = this.hdnUserID.Value;
                taskManagerUserDetailInfo.LineID = this.txtLineID.Text;
                taskManagerUserDetailInfo.AreaID = this.txtAreaID.Text;
                taskManagerUserDetailInfo.PermissionType = this.ddlPermissionType.SelectedValue;
                taskManagerUserDetailInfo.Permission = this.chkAllowCase.Checked ? "Y" : "N";
                taskManagerUserDetailInfo.AllowCase = this.chkAllowCase.Checked ? "Y" : "N";
                taskManagerUserDetailInfo.AllowIps = this.chkAllowIps.Checked ? "Y" : "N";
                taskManagerUserDetailInfo.AllowPallet = this.chkAllowPallet.Checked ? "Y" : "N";
                taskManagerUserDetailInfo.AllowPiece = this.chkAllowPiece.Checked ? "Y" : "N";
                taskManagerUserDetailInfo.Descr = "";
                if (string.IsNullOrEmpty(this.hdnType.Value))
                {
                    taskManagerUserDetailInfo.CreatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = TaskMgtServiceClientProxy.GetInstance().InsertTaskManagerUserDetail(taskManagerUserDetailInfo) + "保存成功！";
                }
                else
                {
                    taskManagerUserDetailInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = TaskMgtServiceClientProxy.GetInstance().UpdateTaskManagerUserDetail(taskManagerUserDetailInfo) + "更新成功！";
                }
                base.Response.Redirect(string.Format("UserLicense.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "2", base.UrlEncode(this.hdnUserID.Value.Trim())), false);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = "保存失败：" + ex.Message;
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlPermissionType, "TASKTYPE");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnUserID.Value = base.Request.QueryString["ID"];
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["LineID"]))
            {
                this.txtLineID.Text = base.Request.QueryString["LineID"];
            }
            if (base.Request.QueryString["type"] != null)
            {
                this.hdnType.Value = base.Request.QueryString["type"];
                this.SetUserLicenseDetailFrom();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetUserLicenseDetailFrom()
        {
            TaskManagerUserDetailInfo taskManagerUserInfo = TaskMgtServiceClientProxy.GetInstance().GetTaskManagerUserDetailByID(this.hdnUserID.Value, this.txtLineID.Text);
            base.DataEntityViewState = taskManagerUserInfo;
            if (taskManagerUserInfo != null)
            {
                this.txtLineID.Text = taskManagerUserInfo.LineID;
                this.txtAreaID.Text = taskManagerUserInfo.AreaID;
                this.ddlPermissionType.SelectedValue = taskManagerUserInfo.PermissionType;
                this.chkAllowCase.Checked = taskManagerUserInfo.AllowCase == "Y";
                this.chkAllowIps.Checked = taskManagerUserInfo.AllowIps == "Y";
                this.chkAllowPallet.Checked = taskManagerUserInfo.AllowPallet == "Y";
                this.chkPermission.Checked = taskManagerUserInfo.Permission == "Y";
                this.chkAllowPiece.Checked = taskManagerUserInfo.AllowPiece == "Y";
            }
        }
    }
}

